import {axios} from '@/utils/request'

// api接口列表
const api = {
    list: '/product',
    listBySku: '/product/listBySku',
    detail: '/product/{spu}',
    basic: '/product/basic',
    add: '/product',
    edit: '/product/{spu}',
    delete: '/product',
    status: '/product/status/{status}',
    skuList: '/product/skuList',
}

// 列表记录
export function list(params) {
    return axios({
        url: api.list,
        method: 'get',
        params
    })
}

/**
 * 根据sku集获取列表记录
 * @param {Array} skuList sku集
 */
export function listBySku(skuList) {
    return axios({
        url: api.listBySku,
        method: 'get',
        params: {skuList}
    })
}

// 商品详情(详细信息)
export function detail(spu) {
    return axios({
        url: api.detail.replace('{spu}', spu),
        method: 'get'
    })
}

// 商品详情(基础信息)
export function basic(goodsId, params) {
    return axios({
        url: api.basic,
        method: 'get',
        params: {goodsId, ...params}
    })
}

/**
 * 更新状态
 * @param {*} status
 * @param {*} data
 */
export function status(status, data) {
    return axios({
        url: api.status.replace('{status}', status),
        method: 'put',
        data
    })
}

/**
 * 新增记录
 * @param {*} data
 */
export function add(data) {
    return axios({
        url: api.add,
        method: 'post',
        data
    })
}

/**
 * 编辑记录
 * @param {*} spu
 * @param {*} data
 */
export function edit(spu, data) {
    return axios({
        url: api.edit.replace('{spu}', spu),
        method: 'put',
        data
    })
}

/**
 * 删除记录
 * @param {*} data
 */
export function deleted(data) {
    return axios({
        url: api.delete,
        method: 'delete',
        data
    })
}

// 列表记录
export function skuList(params) {
    return axios({
        url: api.skuList,
        method: 'get',
        params
    })
}